<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>数组排序</title>
  <script>
    var arr = [1, 9, 4, 0, 6, 0, 11, 3, 2];
    // 1.冒泡排序
    function mySort(arr) {
      // 外层循环控制比多少轮
      for (var i = 0; i <= arr.length - 1; i++) {
        // 内层循环控制一轮比较多少次
        for (var j = 0; j <= arr.length - 1 - i; j++) {
          if (arr[j] > arr[j + 1]) {
            var temp = arr[j];
            arr[j] = arr[j + 1];
            arr[j + 1] = temp;
          }
        }
      }
      console.log(arr);
    }
    // mySort(arr);

    // 2.原生sort方法排序
    let newArr = arr.sort(function (a, b) {
      return b - a
    })
    console.log(newArr);
  </script>
</head>

<body>

</body>

</html>